package rs.etf.es.algorithm;

import java.util.ArrayList;

public class DemoDataExecutor {

    public static final Double INSTANTIATED_VARIABLE = new Double(1);

    /**
     * @param args
     */
    public static void main(String[] args) {

	String[] hVals = { "h1", "h2" };
	String[] bVals = { "b1", "b2" };
	String[] lVals = { "l1", "l2" };
	String[] cVals = { "c1", "c2" };
	Node h = new Node();
	Node b = new Node();
	Node l = new Node();
	Node c = new Node();

	// set names
	h.setName("H");
	b.setName("B");
	l.setName("L");
	c.setName("C");

	h.setAllValues(hVals);
	b.setAllValues(bVals);
	c.setAllValues(cVals);
	l.setAllValues(lVals);

	ArrayList<Node> bParent = new ArrayList<Node>();
	ArrayList<Node> lParents = new ArrayList<Node>();
	ArrayList<Node> cParents = new ArrayList<Node>();
	ArrayList<Node> hChildren = new ArrayList<Node>();
	ArrayList<Node> lChildren = new ArrayList<Node>();
	hChildren.add(b);
	hChildren.add(l);
	lChildren.add(c);
	cParents.add(l);
	bParent.add(h);
	lParents.add(h);
	b.setParents(bParent);
	l.setParents(lParents);
	c.setParents(cParents);
	h.setChildren(hChildren);
	l.setChildren(lChildren);

	// fill node address book
	NodeAddressBook.instance().addNode(c);
	NodeAddressBook.instance().addNode(l);
	NodeAddressBook.instance().addNode(b);
	NodeAddressBook.instance().addNode(h);
	NodeAddressBook.instance().setRoot(h);

	// set CPT values
	h.getMyCPT().setProbability(Node.NO_PARENT, "h1", Node.NO_CONDITION, 0.2);
	h.getMyCPT().setProbability(Node.NO_PARENT, "h2", Node.NO_CONDITION, 0.8);

	b.getMyCPT().setProbability("H", "b1", "h1", 0.25);
	b.getMyCPT().setProbability("H", "b2", "h1", 0.75);
	b.getMyCPT().setProbability("H", "b1", "h2", 0.05);
	b.getMyCPT().setProbability("H", "b2", "h2", 0.95);

	l.getMyCPT().setProbability("H", "l1", "h1", 0.003);
	l.getMyCPT().setProbability("H", "l2", "h1", 0.997);
	l.getMyCPT().setProbability("H", "l1", "h2", 0.00005);
	l.getMyCPT().setProbability("H", "l2", "h2", 0.99995);

	c.getMyCPT().setProbability("L", "c1", "l1", 0.6);
	c.getMyCPT().setProbability("L", "c2", "l1", 0.4);
	c.getMyCPT().setProbability("L", "c1", "l2", 0.02);
	c.getMyCPT().setProbability("L", "c2", "l2", 0.98);

	RequestManager.instance().instantiateVariable("B", "b1");
	RequestManager.instance().instantiateVariable("C", "c1");

	Thread algorithmThread = new Thread(new Algorithm());
	algorithmThread.start();
	try {
	    algorithmThread.join();
	} catch (InterruptedException e) {
	    e.printStackTrace();
	}
    }

}
